document.addEventListener('DOMContentLoaded', function() {
  const filterList = document.getElementById('problem_filter');
  const listItems = filterList.querySelectorAll('li');
  
  // 初始化：检查当前URL参数并设置active
  const urlParams = new URLSearchParams(window.location.search);
  const currentQ = urlParams.get('q');
  
  if (currentQ) {
    listItems.forEach(item => {
      if (item.id === currentQ) {
        item.classList.add('search_filter_active');
      }
    });
  }
  
  // 点击事件：修改URL并切换active
  listItems.forEach(item => {
    item.addEventListener('click', function() {
      // 移除所有active类
      listItems.forEach(li => li.classList.remove('search_filter_active'));
      
      // 为当前点击项添加active
      this.classList.add('search_filter_active');
      
      // 更新URL参数
      const newUrl = new URL(window.location.href);
      newUrl.searchParams.set('q', this.id);
      window.location.href = newUrl;
    });
  });
  //随机颜色
  const colors = ['#fb0909', '#04a9fc', '#5f04fc', '#FFBE0B', '#FF9F1C','#f804fc',"#128938"];
  document.querySelectorAll(".search_filter ul li").forEach(li=>{
    // let color_index=Math.floor(Math.random() * colors.length)
    const hue = Math.floor(Math.random() * 360); // 0-359
    li.style.color = `hsl(${hue}, 100%, 40%)`;     // 深色文字
    li.style.borderColor = `hsl(${hue}, 80%, 60%)`; // 浅色边框
  });
  
});

